package com.xyc.wemedia.user.controller;


import com.xyc.global.bean.Message;
import com.xyc.global.bean.UserDTO;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("user")
public class PermissonController {
    @RequestMapping("login")
    public Message login(@RequestBody UserDTO userDTO){
        Message message = new Message();
        try {
            UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(userDTO.getUsername(), userDTO.getPassword());
            SecurityUtils.getSubject().login(usernamePasswordToken);
            message.setCode(0);
        } catch (Exception e) {
            e.printStackTrace();
            message.setCode(1);
            message.setMsg("用户名或者密码错误");
        }
        return message;
    }
}
